package owl2vowl.parser.vowl;

import owl2vowl.model.AbstractVowlObject;
import owl2vowl.model.annotation.Annotation;
import owl2vowl.model.data.VowlData;
import owl2vowl.parser.helper.IriFormatText;
import owl2vowl.parser.vowl.AnnotationVisitor;
import java.util.function.Consumer;
import org.semanticweb.owlapi.model.OWLOntologyManager;

public class AnnotationParser {
	private final VowlData vowlData;
	private final OWLOntologyManager manager;

	public AnnotationParser(VowlData vowlData, OWLOntologyManager manager) {
		this.vowlData = vowlData;
		this.manager = manager;
	}

	public void parse() {
		this.vowlData.getEntityMap().values().stream().forEach(this::parseForEntity);
	}

	public void parse(AbstractVowlObject vowlObject) {
		this.parseForEntity(vowlObject);
	}

	protected void parseForEntity(AbstractVowlObject entity) {
		entity.accept(new AnnotationVisitor(this.vowlData, this.manager));
		String iriLabel = IriFormatText.cutQuote(IriFormatText.extractNameFromIRI(entity.getIri().toString()));
		Annotation iriAnnotationLabel = new Annotation("label", iriLabel);
		iriAnnotationLabel.setLanguage("IRI-based");
		entity.getAnnotations().addLabel(iriAnnotationLabel);
	}
}